package blog.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import blog.entity.Tag;
import blog.mapper.ArticleTagRefMapper;
import blog.mapper.TagMapper;
import blog.service.TagService;

@Service
public class TagServiceImpl implements TagService {
	@Resource 
	private TagMapper tagMapper;
	@Resource 
	private ArticleTagRefMapper articleTagRefMapper;

	public List<Tag> listTag() {
		List<Tag> tagList = tagMapper.listTag();
		for (int i = 0; i < tagList.size(); i++) {
			Integer count = articleTagRefMapper.countArticleByTagId(tagList.get(i).getTagId());
			tagList.get(i).setArticleCount(count);
		}
		return tagList;
	}

	@Override
	public void add(Tag tag) {
		tagMapper.add(tag);
		
	}

	@Override
	public void deleteTag(Integer tagId) {
		tagMapper.deleteTag( tagId);
	}
}
